/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package biofilter.records.NimbleGen;

import biofilter.records.RecordBase;
import biofilter.exceptions.InvalidRecordException;
import biofilter.util.StringUtil;
import java.text.ParseException;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 * a NimbleGenRawRecord record contains the raw expression levels from an experement run by a NimbleGen Tiling Array.
 * There is no formal way to say what experement is was... other than one file == one experement
 *
 *  Rows look like
    IMAGE_ID        GENE_EXPR_OPTION        SEQ_ID  PROBE_ID        POSITION        X       Y       MATCH_INDEX     SEQ_URL PM      MM
    369133_SLOT01_S01_fullslide_on A1       GAP_1           5351-5924_4     0       992     666     244356842               251.56  0.00
 * @author Daniel Quest
 * @date   Dec 15th 2009
 */
public class NimbleGenRawRecord extends RecordBase {

    public NimbleGenRawRecord(String line){
        record = line;
        setup();
    }

    public NimbleGenRawRecord(){
        record = "";
        setup();
    }
    
    String record = "";
    StringUtil u = null;
    public void setup(){
        u = new StringUtil();
    }

    private String line = "";
    //Rows look like
    //IMAGE_ID        GENE_EXPR_OPTION        SEQ_ID  PROBE_ID        POSITION        X       Y       MATCH_INDEX     SEQ_URL PM      MM
    //369133_SLOT01_S01_fullslide_on A1       GAP_1           5351-5924_4     0       992     666     244356842               251.56  0.00
    String image_id;
    String gene_expr_option;
    String seq_id;
    String probe_id;
    int position;
    int x;
    int y;
    int match_index;
    String url;
    double pm;
    double mm;

    public String get(){ return record; }
    public void set(String line){
        try {
            this.record = line;
            parse(line); //may need to change to lazy initialization
        } catch (InvalidRecordException ex) {
            Logger.getLogger(NimbleGenRawRecord.class.getName()).log(Level.SEVERE, line, ex);
        }
    }
    public void parse(String line) throws InvalidRecordException {
        //System.err.println("test");
        String cols[] = line.split("\t");
        if (cols.length < 9){
            try {
                //System.err.println("Calling split on spaces!");
                cols = u.splitOnSpaces(line, 10);
            } catch (ParseException ex) {
                Logger.getLogger(NimbleGenRawRecord.class.getName()).log(Level.SEVERE, line, ex);
            }
        }
        //System.err.println(cols.length);
        Double dd = new Double("0");
        Integer ll = new Integer("1");
        //System.err.println(cols.length);
        if ( cols.length == 10 || cols.length == 11){
            image_id = cols[0];
            gene_expr_option = cols[1];
            seq_id = cols[2];
            probe_id = cols[3];
            position = ll.parseInt(cols[4]);
            x = ll.parseInt(cols[5]);
            y = ll.parseInt(cols[6]);
            match_index = ll.parseInt(cols[7]);
            url = cols[8];
            pm = dd.parseDouble(cols[9]);
            mm = dd.parseDouble(cols[10]);
        }else{
            throw new InvalidRecordException("KB.Records.NimbleGen.NimbleGenRaw: set malformed record: " + line);
        }
        //TODO:
    }

    public String getGene_expr_option() {
        return gene_expr_option;
    }

    public void setGene_expr_option(String gene_expr_option) {
        this.gene_expr_option = gene_expr_option;
    }

    public String getImage_id() {
        return image_id;
    }

    public void setImage_id(String image_id) {
        this.image_id = image_id;
    }

    public int getMatch_index() {
        return match_index;
    }

    public void setMatch_index(int match_index) {
        this.match_index = match_index;
    }

    public double getMm() {
        return mm;
    }

    public void setMm(double mm) {
        this.mm = mm;
    }

    public double getPm() {
        return pm;
    }

    public void setPm(double pm) {
        this.pm = pm;
    }

    public int getPosition() {
        return position;
    }

    public void setPosition(int position) {
        this.position = position;
    }

    public String getProbe_id() {
        return probe_id;
    }

    public void setProbe_id(String probe_id) {
        this.probe_id = probe_id;
    }

    public String getSeq_id() {
        return seq_id;
    }

    public void setSeq_id(String seq_id) {
        this.seq_id = seq_id;
    }

    public String getUrl() {
        return url;
    }

    public void setUrl(String url) {
        this.url = url;
    }

    public int getX() {
        return x;
    }

    public void setX(int x) {
        this.x = x;
    }

    public int getY() {
        return y;
    }

    public void setY(int y) {
        this.y = y;
    }



    public String format(){
        String s = "";
        //s+= seqid;
        //s+= "\t" + source;
        //s+= "\t" + type;
        //s+= "\t" + start;
        //s+= "\t" + end;
        //s+= "\t" + score;
        //s+= "\t" + strand;
        //s+= "\t" + phase;
        //s+= "\t" + attributes;
        //s+= "\n";
        return s;
    }

}